%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% The Effect of Inequality and Social Identity on Party Strategies %%%%%%%
%%%%%%%%%% Margit Tavits and Joshua D. Potter %%%%%%%%%%%%%%%%%%
%%%%%%%% Replication Files with Stata Commands %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% prepare the data for analysis 

drop if exclude == 1
drop if part1 == 1
drop if part9 == 1
drop if part10 == 1 
drop if part11 == 1 
drop if part12 == 1 
drop if part13 == 1 
drop if countryname == "Azerbaijan" 
drop if countryname == "Belarus" 
drop if countryname == "German Democratic Republic" 
drop if countryname == "Northern Ireland" 
drop if countryname == "Sri Lanka" 
drop if countryname == "Mexico"  

%% Table 1 

xtmixed econ_sum right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
lincom gini_gross + (0)*right4_ginig, level(95)
lincom gini_gross + (1)*right4_ginig, level(95)

xtmixed val_sum right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
lincom gini_gross + (0)*right4_ginig, level(95)
lincom gini_gross + (1)*right4_ginig, level(95) 

%% Table SI.10 (Regression Analysis Underlying Figures 1 and 2 in Main Text)

gen eth_gini = gini_gross*al_ethnic
xtmixed val_sum gini_gross al_ethnic eth_gini newparty niche pervote gdpg enpv newdem if right4==1, level(95), || country:, || party:

gen relig_gini = gini_gross*al_religion
xtmixed val_sum gini_gross al_religion relig_gini newparty niche pervote gdpg enpv newdem if right4==1, level(95), || country:, || party:

gen church2_gini = gini_gross*church2 
xtmixed val_sum gini_gross church2 church2_gini newparty niche pervote gdpg enpv newdem if right4==1, level(95), || country:, || party:

gen foreign_gini = gini_gross*foreign
xtmixed val_sum gini_gross foreign foreign_gini newparty niche pervote gdpg enpv newdem if right4==1, level(95), || country:, || party:

xtmixed val_sum gini_gross foreign foreign_gini newparty niche pervote gdpg enpv newdem if right4==1 & we==1, level(95), || country:, || party:

%% Table SI.5

xtmixed econ_sum right4 gini_gross right4_ginig newparty niche pervote lag_newpts unemploy soc_spend bgi foreign gdpg enpv newdem, level(95), || country:, || party:

lincom gini_gross + (0)*right4_ginig, level(95)
lincom gini_gross + (1)*right4_ginig, level(95)

xtmixed val_sum right4 gini_gross right4_ginig newparty niche pervote lag_newpts unemploy  soc_spend bgi foreign gdpg enpv newdem, level(95), || country:, || party:

lincom gini_gross + (0)*right4_ginig, level(95)
lincom gini_gross + (1)*right4_ginig, level(95)

%% Table SI.6

gen mper401 = per402 + per403 + per404 + per406 + per407 + per409 +  per412 + per413 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper402= per401 +  per403 + per404 + per406 + per407 + per409 +  per412 + per413 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper403= per401 + per402 + per404 + per406 + per407 + per409 +  per412 + per413 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper404= per401 + per402 + per403 + per406 + per407 + per409 +  per412 + per413 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper406= per401 + per402 + per403 + per404 +  per407 + per409 +  per412 + per413 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper407= per401 + per402 + per403 + per404 + per406 + per409 +  per412 + per413 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper409= per401 + per402 + per403 + per404 + per406 + per407 +  per412 + per413 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper412= per401 + per402 + per403 + per404 + per406 + per407 + per409 + per413 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper413= per401 + per402 + per403 + per404 + per406 + per407 + per409 +  per412 + per414 + per503 + per504 + per505 +   per701 + per702 
gen mper414= per401 + per402 + per403 + per404 + per406 + per407 + per409 +  per412 + per413 + per503 + per504 + per505 +   per701 + per702 
gen mper503= per401 + per402 + per403 + per404 + per406 + per407 + per409 +  per412 + per413 + per414 +  per504 + per505 +   per701 + per702 
gen mper504= per401 + per402 + per403 + per404 + per406 + per407 + per409 +  per412 + per413 + per414 + per503 + per505 +   per701 + per702 
gen mper505= per401 + per402 + per403 + per404 + per406 + per407 + per409 +  per412 + per413 + per414 + per503 + per504 +  per701 + per702 
gen mper701= per401 + per402 + per403 + per404 + per406 + per407 + per409 +  per412 + per413 + per414 + per503 + per504 + per505 +   per702 
gen mper702= per401 + per402 + per403 + per404 + per406 + per407 + per409 +  per412 + per413 + per414 + per503 + per504 + per505 +   per701  

xtmixed econ_sum right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper401 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper402 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper403 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper404 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper406 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper407 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper409 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper412 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper413 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper414 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper503 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper504 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper505 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper701 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper702 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:

gen mper601= per602 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052        
gen mper602= per601 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052     
gen mper603= per601 + per602 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052         
gen mper604= per601 + per602 + per603 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052        
gen mper605= per601 + per602 + per603 + per604 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052        
gen mper606= per601 + per602 + per603 + per604 + per605 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052        
gen mper607= per601 + per602 + per603 + per604 + per605 + per606 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052        
gen mper608= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052         
gen mper705= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per608 + per706 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052         
gen mper706= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per2022 + per2023 + per6072 + per6081 + per7051 + per7052         
gen mper2022= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2023 + per6072 + per6081 + per7051 + per7052         
gen mper2023= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per6072 + per6081 + per7051 + per7052         
gen mper6072= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6081 + per7051 + per7052        
gen mper6081= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per7051 + per7052        
gen mper7051= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7052        
gen mper7052= per601 + per602 + per603 + per604 + per605 + per606 + per607 + per608 + per705 + per706 + per2022 + per2023 + per6072 + per6081 + per7051         

xtmixed val_sum right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper601 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper602 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper603 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper604 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper605 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper606 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper607 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper608 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper705 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper706 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper2022 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party: 
xtmixed mper2023 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper6072 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper6081 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper7051 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
xtmixed mper7052 right4 gini_gross right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:

%% Table SI.7

xtmixed bal_interval gini_gross right4 right4_ginig newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:

lincom gini_gross + (0)*right4_ginig, level(95)
lincom gini_gross + (1)*right4_ginig, level(95) 

%% Table SI.8

gen right_top1 = right4*top1
xtmixed econ_sum top1 right4 right_top1 newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
lincom top1 + (0)*right_top1, level(95)
lincom top1 + (1)*right_top1, level(95)

xtmixed val_sum top1 right4 right_top1 newparty niche pervote gdpg enpv newdem, level(95), || country:, || party:
lincom top1 + (0)*right_top1, level(95)
lincom top1 + (1)*right_top1, level(95) 

%% Table SI.9

generate turnout_gini = turnoutidea*gini_gross

xtmixed econ_sum gini_gross newparty niche pervote gdpg enpv newdem if right4==0 & turnoutidea!=., level(95), || country:, || party:

xtmixed econ_sum gini_gross turnoutidea turnout_gini newparty niche pervote gdpg enpv newdem if right4==0, level(95), || country:, || party:

%% Table SI.11

egen z1 = std(al_ethnic)
egen z2 = std(al_religion)
egen z3 = std(church2)
egen z4 = std(foreign)
gen demand = z1+z2+z3+z4
gen demand_gini = gini_gross*demand
xtmixed val_sum gini_gross demand demand_gini newparty niche pervote gdpg enpv newdem if right4==1, level(95), || country:, || party: